$(function () {
    map();

    function map() {
        var myChart = echarts.init(document.getElementById('chart_guizhou'));

        var data = [
            //可以随意更改名称，但是名称与geo中的名称需对应，将来作为发电站的地理坐标
            {name: '遵义风电站', value: 63, icon:'images/yellow.png'},
            {name: '贵阳', value: 71, icon:'images/blue.png'},
            {name: '毕节', value: 90, icon:'images/yellow.png'},
            {name: '六盘水', value: 90, icon:'images/blue.png'},
            {name:'安顺市',value:23, icon:'images/blue.png'},
            {name:'铜仁地区',value:45, icon:'images/blue.png'},
            {name:'兴义市',value:75, icon:'images/blue.png'}
        ];

        var geoCoordMap = {
            '遵义风电站':[106.9,27.7],
            '贵阳':[106.71,26.57],
            '毕节':[105.86,27.25],
            '六盘水':[104.83,26.6],
            '安顺市':[105.95,26.25],
            '铜仁地区':[109.18,27.72],
            '兴义市':[104.9,25.08],
        };

        var convertData = function (data) {
            var res = [];
            for (var i = 0; i < data.length; i++) {
                var geoCoord = geoCoordMap[data[i].name];
                if (geoCoord) {
                    res.push({
                        name: data[i].name,
                        value: geoCoord.concat(data[i].value),
                        symbol: 'image://' + data[i].icon // 添加 symbol 字段
                    });
                }
            }
            return res;
        };

        var option = {
			layoutCenter: ['50%', '50%'],//位置
			layoutSize:'60%',//大小
			
            tooltip : {
                trigger: 'item',
                formatter: function (params) {
                    if(typeof(params.value)[2] == "undefined"){
                        return params.name + ' : ' + params.value;
                    }else{
                        return params.name + ' : ' + params.value[2];
                    }
                }
            },
            geo: {
                map: '贵州',
                label: {
                    emphasis: {
                        show: false
                    }
                },
                roam: false,
                itemStyle: {
                    normal: {
                        areaColor: '#4c60ff',
                        borderColor: '#002097'
                    },
                    emphasis: {
                        areaColor: '#293fff'
                    }
                }
            },
            series : [
                {
                    name: '贵州坐标散点图',
                    type: 'scatter',
                    coordinateSystem: 'geo',
                    data: convertData(data),
                    symbolSize: function (val) {
						console.log(val)
                        return val[2] / 15;
                    },
                    label: {
                        normal: {
                            formatter: '{b}',
                            position: 'right',
                            show: false
                        },
                        emphasis: {
                            show: true
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#ffeb7b',
                        },
                        emphasis: {
                            color: '#ffd800'
                        }
                    },
					symbol: 'image://images/blue.png',
                    symbolSize: [15, 20]
                }
            ]
        };

        myChart.setOption(option);

        window.addEventListener("resize",function(){
            myChart.resize();
        });
    }
})
